package com.xc.smart.controller;

import com.xc.smart.annotation.Login;
import com.xc.smart.annotation.LoginUser;
import com.xc.smart.entity.Blog;
import com.xc.smart.entity.User;
import com.xc.smart.entity.dto.BlogDto;
import com.xc.smart.service.BlogService;
import com.xc.smart.utlis.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import java.util.List;

/**
 * @author mtl
 * 2021/6/9
 */
@Controller
@RequestMapping("/bolg")
public class BolgController {

    @Resource
    BlogService blogService;


//    @RolesAllowed("ADMIN")
    @GetMapping("/list")
    @ResponseBody
    public R selectList(@LoginUser User user,
                        @RequestParam(value = "page",defaultValue = "1") Integer page,
                        @RequestParam(value = "sort",required = false) Integer sort){
        List<Blog> list = blogService.selectBlogList(page, sort);
        return R.ok().put("list",list).put("user",user);
    }

    @GetMapping("/getUser")
    @ResponseBody
    public R getUsers(@LoginUser User user){
        return R.ok().put("user",user);
    }

    @Login
    @PostMapping("/insert")
    @ResponseBody
    public R insertBolg(@LoginUser User user, BlogDto dto){
        R r = blogService.InsertBolg(user, dto);
        return r;
    }


}
